package com.gitee.wsl.struct.command.model.parameters.types

import com.gitee.wsl.struct.command.model.parameters.arguments.delegate.ProcessedArgument
import com.gitee.wsl.struct.command.model.parameters.arguments.delegate.RawArgument
import com.gitee.wsl.struct.command.model.parameters.arguments.delegate.convert
import com.gitee.wsl.struct.command.model.parameters.options.delegate.OptionWithValues
import com.gitee.wsl.struct.command.model.parameters.options.delegate.RawOption
import com.gitee.wsl.struct.command.model.parameters.options.tran.convert
import com.gitee.wsl.struct.command.model.parameters.TransformContext

private val conversion: TransformContext.(String) -> Float =
    { it.toFloatOrNull() ?: fail(context.localization.floatConversionError(it)) }

/** Convert the argument values to a `Float` */
fun RawArgument.float(): ProcessedArgument<Float, Float> = convert(conversion = conversion)

/** Convert the option values to a `Float` */
fun RawOption.float(): OptionWithValues<Float?, Float, Float> =
    convert({ localization.floatMetavar() }, conversion = conversion)
